<?php class MDn extends CI_Model {
	
	function __construct()
	    {
		parent::__construct();
	    }

	function insertVille($data){
		return $this->db->insert('ville', $data);
	}

	function insertP1($data){
		return $this->db->insert('patient', $data);
	}


	function insertC1($data){
		return $this->db->insert('clinique', $data);
	}	

	function insertDD($data){
		return $this->db->insert('demandeDevis', $data);
	}

	function insertDentiste($data){
		return $this->db->insert('dentiste', $data);
	}
	
	function insertExpDentiste($data){
		return $this->db->insert('expProf', $data);
	}
	
	function insertdevisTemp($data){
		return $this->db->insert('devisTemp', $data);
	}	

	function insertDevisTableau($data){
		return $this->db->insert('devistableau', $data);
	}
	
	function updatedevistemp($data1) {
	    $data = array(
		'id_patient' => $data1['id_patient'], 
		'listclinicvalue' => $data1['listclinicvalue']
	    );
	    $this->db->where('id_patient',$data1['id_patient']);
	    $this->db->update('devisTemp', $data);
	} 


	function getInfoDevisTemp($idpatient) {
		$sql = "SELECT * FROM devisTemp WHERE id_patient = ?";			
		$Q = $this->db->query($sql, array($idpatient));
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function modifMdpPatient($data1) {
	    $data = array(
				'id_patient' => $data1['id_patient'], 
				'mdp' => $data1['mdp']
			);
	    $this->db->where('id_patient',$data1['id_patient']);
	    $this->db->update('patient', $data);
	} 
	
	
	function modifMdpClinic($data1) {
	    $data = array(
				'id_clinique' => $data1['id_clinique'], 
				'mdp' => $data1['mdp']
			);
	    $this->db->where('id_clinique',$data1['id_clinique']);
	    $this->db->update('clinique', $data);
	} 
	
	
	function updateP1($data1) {
	    $data = array(
				'id_patient' => $data1['id_patient'], 
				'nom' => $data1['nom'],
				'prenom' => $data1['prenom'],
				'date_naissance' => $data1['date_naissance'],				
				'adresse' => $data1['adresse'],
				'tel_fixe' => $data1['tel_fixe'],
				'tel_mobile' => $data1['tel_mobile'],
				'id_ville' => $data1['id_ville'],
				'id_pays' => $data1['id_pays'],
				'email' => $data1['email'],
				'mdp' => $data1['mdp'],
				'code_postal' => $data1['code_postal']
			);
	    $this->db->where('id_patient',$data1['id_patient']);
	    $this->db->update('patient', $data);
	} 

	function updateC1($data1) {
		//echo "mija".$data1['id_clinique'];
	    $data = array(
				'id_clinique' => $data1['id_clinique'], 
				/*'logo' =>  $data1['logo'],*/
				'nom_clinique'=> $data1['nom_clinique'],
				'id_ville'=> $data1['id_ville'], 
				'id_pays'=> $data1['id_pays'], 
				'adresse'=> $data1['adresse'], 
				/*'photo1' => $data1['photo1'], 
				'photo2' => $data1['photo2'], 
				'photo3' => $data1['photo3'], 
				'photo4' => $data1['photo4'], 
				'photo5' =>  $data1['photo5'], 
				'photo6' =>  $data1['photo6'], 
				'photo7' =>  $data1['photo7'], 
				'photo8' =>  $data1['photo8'], 
				'photo9' =>  $data1['photo9'], 
				'photo10' =>  $data1['photo10'],*/ 
				'prothese'=> $data1['prothese'], 
				'scanner'=> $data1['scanner'], 
				'origine_materiaux1'=> $data1['origine_materiaux1'], 
				'origine_materiaux2'=> $data1['origine_materiaux2'], 
				'origine_materiaux3'=> $data1['origine_materiaux3'], 
				'fauteuil'=> $data1['fauteuil'], 
				'surface'=> $data1['surface'],
				'marque_implant1'=> $data1['marque_implant1'],
				'marque_implant2'=> $data1['marque_implant2'],
				'marque_implant3'=> $data1['marque_implant3'],
				'code_postal'=> $data1['code_postal'],
				'isInfoUpdate'=> $data1['isInfoUpdate']
			);
	    $this->db->where('id_clinique',$data1['id_clinique']);
	    $this->db->update('clinique', $data);
	} 

	function recupLastInsertDentiste($id_clinique){
		$id_dentiste = "";
		$sql = "SELECT * FROM dentiste WHERE id_clinique = $id_clinique AND id_dentiste =LAST_INSERT_ID();";		
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$id_dentiste = $row['id_dentiste'];
			}
			return $id_dentiste;
		}
		$Q->free_result();
	}

	function updateDentiste($data1) {
	    $data = array(
				'id_dentiste' => $data1['id_dentiste'],
				'id_clinique' => $data1['id_clinique'],
				'photo_dentiste'=> $data1['photo_dentiste'],
				'nom_dentiste'=> $data1['nom_dentiste'], 
				'fonction_dentiste'=> $data1['fonction_dentiste'], 				
				'langue1'=> $data1['langue1'], 
				'langue2'=> $data1['langue2'], 
				'langue3'=> $data1['langue3']
			);
	    $this->db->where('id_dentiste',$data1['id_dentiste']);
	    $this->db->update('dentiste', $data);
	} 
	
	function updateExpDentiste($data1) {
	    $data = array(
				'id_expProf' => $data1['id_expProf'],
				'exp' => $data1['exp'],
				'annee1' => $data1['annee1'],
				'annee2'=>$data1['annee2']
			);
	    $this->db->where('id_expProf',$data1['id_expProf']);
	    $this->db->update('expProf', $data);
	} 
	
	function updateLogoC1($data1) {
	    $data = array(
				'id_clinique' => $data1['id_clinique'], 
				'logo'=> $data1['logo']
			);
	    $this->db->where('id_clinique',$data1['id_clinique']);
	    $this->db->update('clinique', $data);
	} 
 
	
	function updateImgPpleC1($data1) {
	    $data = array(
				'id_clinique' => $data1['id_clinique'], 
				'image_principale'=> $data1['image_principale']
			);
	    $this->db->where('id_clinique',$data1['id_clinique']);
	    $this->db->update('clinique', $data);
	} 
	/*function updateImagePpleC1($data1) {
	    $data = array(
				'id_clinique' => $data1['id_clinique'], 
				'image_principale'=> $data1['image_principale']
			);
	    $this->db->where('id_clinique',$data1['id_clinique']);
	    $this->db->update('clinique', $data);
	} */
	function insertImageGallerie($data1){
		return $this->db->insert('galerieImage', $data1);
	}	

	function insertPhotoSoins($data1){
		return $this->db->insert('photoSoin', $data1);
	}	
	
	function verifDD($id_patient) {
		$sql = "SELECT * FROM demandeDevis WHERE id_patient = ?";			
		$Q = $this->db->query($sql, array($id_patient));
		if ($Q->num_rows()>0){
			return 1;
		}
		return 0;
	}
	
	function updateDD($data1) {
	    $data = array(
				'budget1' => $data1['budget1'], 
				'budget2' => $data1['budget2'], 
				'solution_souhaite' => $data1['solution_souhaite'], 
				'nb_traitement' => $data1['nb_traitement'], 
				'moment_soin' => $data1['moment_soin'], 
				'antecedent' => $data1['antecedent'], 
				'diabete' => $data1['diabete'], 
				'tension' => $data1['tension'], 
				'dialyse' => $data1['dialyse'], 
				'greffe' => $data1['greffe'], 
				'insuf_card' => $data1['insuf_card'], 
				'hemophilie' => $data1['hemophilie'], 
				'autre_antecedent' => $data1['autre_antecedent'],
				'photo1' => $data1['photo1'],
				'photo2' => $data1['photo2'],
				'photo3' => $data1['photo3'],
				'photo4' => $data1['photo4'],
				'photo5' => $data1['photo5'], 
				'premiere_langue' => $data1['premiere_langue'], 
				'deuxieme_langue' => $data1['deuxieme_langue'], 
				'souhait' => $data1['souhait'], 
				'voyage' => $data1['voyage'],
				'id_patient' => $data1['id_patient']
			);
	    $this->db->where('id_patient',$data1['id_patient']);
	    $this->db->update('demandeDevis', $data);
	} 
	
	function getInfoPatient($email) {
		$sql = "SELECT * FROM patient WHERE email = ?";			
		$Q = $this->db->query($sql, array($email));
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function getMessageByIdMsg($id_message) {
		$sql = "SELECT * FROM message WHERE id_message = ?";			
		$Q = $this->db->query($sql, array($id_message));
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}

	function getCommentaireByIdclinique($id_clinique) {
		$sql = "SELECT * FROM commentaire WHERE id_clinique = '$id_clinique' AND isValid = '1' ";			
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function getLogoImagePple($id_clinique) {
		$sql = "SELECT * FROM clinique WHERE id_clinique = ?";			
		$Q = $this->db->query($sql, array($id_clinique));
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}

	function getGalPhoto($id_clinique) {
		$sql = "SELECT * FROM galerieImage WHERE id_clinique = '$id_clinique'";	
		//echo $sql;
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function getFirstImgGalPhoto($id_clinique) {
		$sql = "SELECT * FROM clinique WHERE id_clinique ='$id_clinique' ";	
		//echo $sql;
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function getSecondImgGalPhoto($id_clinique) {
		$sql = "SELECT * FROM galerieImage WHERE id_clinique = '$id_clinique'ORDER BY id_galerieImage ASC LIMIT 1 , 2";	
		//echo $sql;
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}

	function getSoinPhoto($id_clinique) {
		$sql = "SELECT * FROM photoSoin WHERE id_clinique = ?";			
		$Q = $this->db->query($sql, array($id_clinique));
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}

	function getInfoPatientId($id_patient) {
		$sql = "SELECT * FROM patient WHERE id_patient = ?";			
		$Q = $this->db->query($sql, array($id_patient));
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function verifEmailPatient($email) {
		$sql = "SELECT * FROM patient WHERE email = ?";			
		$Q = $this->db->query($sql, array($email));
		if ($Q->num_rows()>0){
			return 1;
		}
		return 0;
	}

	function verifComptePatient($email,$mdp) {
		$sql = "SELECT * FROM patient WHERE email = '$email' AND mdp = '$mdp'";
		$Q = $this->db->query($sql);		
		$id = 0;
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$id = $row['id_patient'];
			}
		}
		$Q->free_result();
		return $id;
	}

	function recupIddevisRecus($id_clinique,$id_patient) {
		$sql = "SELECT id_devisRecus FROM devisRecus WHERE id_clinique = '$id_clinique' AND id_patient = '$id_patient'";
		$Q = $this->db->query($sql);		
		$id = 0;
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$id = $row['id_devisRecus'];
			}
		}
		$Q->free_result();
		return $id;
	}
	
	function recupIddemandedevis($id_patient) {
		$sql = "SELECT id_demandeDevis FROM demandeDevis WHERE id_patient = '$id_patient'";
		//echo $sql;
		$Q = $this->db->query($sql);		
		$id = 0;
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$id = $row['id_demandeDevis'];
			}
		}
		$Q->free_result();
		return $id;
	}
	
	function verifDevisPatient($id_patient, $id_clinique) {
		$sql = "SELECT * FROM devisRecus WHERE id_patient = '$id_patient' AND id_clinique = '$id_clinique' ";
		$Q = $this->db->query($sql);		
		$id = 0;
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$id = $row['id_devisRecus'];
			}
		}
		$Q->free_result();
		return $id;
	}

	function recupPreviousClinic($id_clinique) {
		$sql = "SELECT * FROM clinique WHERE id_clinique < '$id_clinique'  ORDER BY id_clinique DESC LIMIT 1";
		$Q = $this->db->query($sql);		
		$id = 0;
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$id = $row['id_clinique'];
			}
		}
		$Q->free_result();
		return $id;
	}
	
	function recupNextClinic($id_clinique) {
		$sql = "SELECT * FROM clinique WHERE id_clinique > '$id_clinique'  ORDER BY id_clinique DESC LIMIT 1";
		$Q = $this->db->query($sql);		
		$id = 0;
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$id = $row['id_clinique'];
			}
		}
		$Q->free_result();
		return $id;
	}
	
	function verifEmailClinic($email) {
		$sql = "SELECT * FROM clinique WHERE email = ?";			
		$Q = $this->db->query($sql, array($email));
		if ($Q->num_rows()>0){
			return 1;
		}
		return 0;
	}
	
	function verifCompteClinic($email,$mdp) {
		$sql = "SELECT * FROM clinique WHERE email = '$email' AND mdp = '$mdp'";	
		$Q = $this->db->query($sql);		
		$id = 0;
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$id = $row['id_clinique'];
			}
		}
		$Q->free_result();
		return $id;
	}
	
	function verifInfoClinic($email,$mdp) {
		$sql = "SELECT * FROM clinique WHERE email = '$email' AND mdp = '$mdp' ";	
		$Q = $this->db->query($sql);		
		$isInfoUpdate = 0;
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$isInfoUpdate = $row['isInfoUpdate'];
			}
		}
		$Q->free_result();
		return $isInfoUpdate;
	}

	function getInfoClinic($email) {
		$sql = "SELECT * FROM clinique WHERE email = ?";			
		$Q = $this->db->query($sql, array($email));
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function getAllDentiste($id_clinique) {
			$sql = "SELECT * FROM dentiste WHERE id_clinique = '$id_clinique' ";
			$Q = $this->db->query($sql);
			if ($Q->num_rows()>0){
				foreach ($Q->result_array() as $row){
					$data[]=$row;
				}
				return $data;
			}
			$Q->free_result();
			return 0;
	}
	
	function getAllExpProfDentiste($id_dentiste) {
			$sql = "SELECT * FROM expProf WHERE id_dentiste  = '$id_dentiste ' ";
			
			$Q = $this->db->query($sql);
			if ($Q->num_rows()>0){
				foreach ($Q->result_array() as $row){
					$data[]=$row;
				}
				return $data;
			}
			$Q->free_result();
			return 0;
	}

	function getDentisteToModif($id_dentiste) {
			$sql = "SELECT * FROM dentiste WHERE id_dentiste = '$id_dentiste' ";			
			//echo $sql;
			$Q = $this->db->query($sql);
			if ($Q->num_rows()>0){
				foreach ($Q->result_array() as $row){
					$data[]=$row;
				}
				return $data;
			}
			$Q->free_result();
			return 0;
	}
	
	function getConditionEtGarantie($id_clinique) {
			$sql = "SELECT * FROM conditionGarantie WHERE id_clinique = '$id_clinique'";			
			$Q = $this->db->query($sql);
			if ($Q->num_rows()>0){
				foreach ($Q->result_array() as $row){
					$data[]=$row;
				}
				$Q->free_result();
				return $data;
			}
			else {
				return 0;
			}
	}
	
	function updateConditionEtGarantie($data1) {
	    $data = array(
				'id_clinique' => $data1['id_clinique'], 
				'accompagnatrice'=> $data1['accompagnatrice'],
				'implant'=> $data1['implant'], 
				'prothese'=> $data1['prothese'], 
				'inlay_Onlay'=> $data1['inlay_Onlay'], 
				'passeportdentaire'=> $data1['passeportdentaire']
			);
	    $this->db->where('id_clinique',$data1['id_clinique']);
	    $this->db->update('conditionGarantie', $data);
	} 
	
	function updateIddevisRecus($typedevis, $id_devisRecus){
	    $data = array(
				'id_devisRecus' => $id_devisRecus, 
				'typedevis'=> $typedevis
			);
	    $this->db->where('id_devisRecus',$id_devisRecus);
	    $this->db->update('devisRecus', $data);
	} 
	
	function updateEmailClinic($email, $id_clinic){
	    $data = array(
				'id_clinique' => $id_clinic, 
				'email'=> $email
			);
	    $this->db->where('id_clinique',$id_clinic);
	    $this->db->update('clinique', $data);
	} 
	
	function updateEmailPatient($email, $id_patient){
	    $data = array(
				'id_patient' => $id_patient, 
				'email'=> $email
			);
	    $this->db->where('id_patient',$id_patient);
	    $this->db->update('patient', $data);
	} 
	
	function updateLocaliteClinic($adresse, $code_postal, $map, $id_pays, $id_ville, $id_clinic){
	    $data = array(
				'id_clinique' => $id_clinic, 
				'adresse'=> $adresse,
				'id_ville' => $id_ville, 
				'id_pays'=> $id_pays,
				'code_postal' => $code_postal,
				'map' => $map
			);
	    $this->db->where('id_clinique',$id_clinic);
	    $this->db->update('clinique', $data);
	} 
	
	function updateLocalitePatient($adresse, $code_postal, $id_pays, $id_ville, $id_patient){
	    $data = array(
				'id_patient' => $id_patient, 
				'adresse'=> $adresse,
				'id_ville' => $id_ville, 
				'id_pays'=> $id_pays,
				'code_postal' => $code_postal
			);
	    $this->db->where('id_patient',$id_patient);
	    $this->db->update('patient', $data);
	} 
	
	function updateMeJoindrePatient($email, $tel_fixe, $tel_mobile, $id_patient,$isPartageContact1,$isPartageContact2){
	    $data = array(
				'id_patient' => $id_patient, 
				'email'=> $email,
				'tel_fixe' => $tel_fixe, 
				'tel_mobile'=> $tel_mobile,
                                'isPartageContact1'=>$isPartageContact1,
                                'isPartageContact2'=>$isPartageContact2
			);
	    $this->db->where('id_patient',$id_patient);
	    $this->db->update('patient', $data);
	} 
	
	function updateBlocClinic($nom_clinique, $prothese, $scanner, $surface, $fauteuil, $id_clinic,$presentationFr,$presentationEn,$presentationDe){
	    $data = array(
				'id_clinique' => $id_clinic, 
				'nom_clinique'=> $nom_clinique,
				'prothese' => $prothese, 
				'scanner'=> $scanner,
				'surface' => $surface,
				'fauteuil' => $fauteuil,
                                'presentationFr' => $presentationFr,
                                'presentationEn' => $presentationEn,
                                'presentationDe' => $presentationDe
			);
	    $this->db->where('id_clinique',$id_clinic);
	    $this->db->update('clinique', $data);
	} 

	function updateBlocSiteweb($siteweb, $lienretour, $id_clinic){
	    $data = array(
				'id_clinique' => $id_clinic, 
				'siteweb'=> $siteweb,
				'lienretour' => $lienretour
			);
	    $this->db->where('id_clinique',$id_clinic);
	    $this->db->update('clinique', $data);
	} 
	
	function updateBlocOrganisation($accompagnatrice, $transfert, $reservation, $reservationBillet, $id_clinic){
	    $data = array(
				'id_clinique' => $id_clinic, 
				'accompagnatrice' => $accompagnatrice, 
				'transfert'=> $transfert,
				'reservation' => $reservation,
				'reservationBillet' => $reservationBillet
			);
	    $this->db->where('id_clinique',$id_clinic);
	    $this->db->update('conditionGarantie', $data);
	} 
	
	function updateBlocGarantie($passeportdentaire, $implant, $prothese, $inlay_Onlay, $id_clinique){
	    $data = array(
				'id_clinique' => $id_clinique, 
				'passeportdentaire' => $passeportdentaire, 
				'implant'=> $implant,
				'prothese' => $prothese,
				'inlay_Onlay' => $inlay_Onlay
			);
	    $this->db->where('id_clinique',$id_clinique);
	    $this->db->update('conditionGarantie', $data);
	} 

	function updateBlocReglement($cartecredit, $monnaie, $id_clinique){
	    $data = array(
				'id_clinique' => $id_clinique, 
				'cartecredit' => $cartecredit, 
				'monnaie'=> $monnaie
			);
	    $this->db->where('id_clinique',$id_clinique);
	    $this->db->update('conditionGarantie', $data);
	} 
	function updateQuiSuisJePatient($civilite, $nom, $prenom, $date_naissance, $id_patient){
	    $data = array(
				'id_patient' => $id_patient, 
				'civilite'=> $civilite,
				'nom' => $nom, 
				'prenom' => $prenom, 
				'date_naissance'=> $date_naissance
			);
	    $this->db->where('id_patient',$id_patient);
	    $this->db->update('patient', $data);
	} 
	
	function updateDemandeDevisSoinSouhaite($budget1, $budget2, $solution_souhaite, $nb_traitement, $moment_soin, $id_patient){
	    $data = array(
				'id_patient' => $id_patient, 
				'budget1'=> $budget1,
				'budget2' => $budget2, 
				'solution_souhaite' => $solution_souhaite, 
				'nb_traitement'=> $nb_traitement,
				'moment_soin'=> $moment_soin
			);
	    $this->db->where('id_patient',$id_patient);
	    $this->db->update('demandeDevis', $data);
	} 
	
	function updateDemandeDevisImages($photo1, $photo2, $photo3, $photo4, $photo5, $id_patient){
	    $data = array(
				'photo1' => $photo1, 
				'photo2'=> $photo2,
				'photo3' => $photo3, 
				'photo4' => $photo4, 
				'photo5'=> $photo5,
				'id_patient'=> $id_patient
			);
	    $this->db->where('id_patient',$id_patient);
	    $this->db->update('demandeDevis', $data);
	} 

	
	function updateDemandeDevisAntMed($diabete, $tension, $dialyse, $greffe, $insuf_card, $hemophilie, $autre_antecedent, $antecedent, $id_patient){
	    $data = array(
				'id_patient' => $id_patient, 
				'diabete'=> $diabete,
				'tension' => $tension, 
				'dialyse' => $dialyse, 
				'greffe'=> $greffe,
				'insuf_card'=> $insuf_card,
				'hemophilie'=> $hemophilie,
				'autre_antecedent'=> $autre_antecedent,
				'antecedent'=> $antecedent
			);
	    $this->db->where('id_patient',$id_patient);
	    $this->db->update('demandeDevis', $data);
	} 
	
	function updateDemandeDevisCom($premiere_langue, $deuxieme_langue, $voyage, $souhait, $id_patient){
	    $data = array(
				'id_patient' => $id_patient, 
				'premiere_langue'=> $premiere_langue,
				'deuxieme_langue' => $deuxieme_langue, 
				'voyage' => $voyage, 
				'souhait'=> $souhait
			);
	    $this->db->where('id_patient',$id_patient);
	    $this->db->update('demandeDevis', $data);
	} 
	
	function verifCG($id_clinique) {
		$sql = "SELECT * FROM conditionGarantie WHERE id_clinique = ?";			
		$Q = $this->db->query($sql, array($id_clinique));
		if ($Q->num_rows()>0){
			return 1;
		}
		return 0;
	}
	
	function insertConditionEtGarantie($data){
		return $this->db->insert('conditionGarantie', $data);
	}
	
	function insertMsgClinic($data){
		return $this->db->insert('message', $data);
	}
	
	function insertCommentPatient($data){
		return $this->db->insert('commentaire', $data);
	}
	
	function getAllImageGalerie($id_clinique) {
			$sql = "SELECT * FROM galerieImage WHERE id_clinique = ?";			
			$Q = $this->db->query($sql, array($id_clinique));
			if ($Q->num_rows()>0){
				foreach ($Q->result_array() as $row){
					$data[]=$row;
				}
				return $data;
			}
			$Q->free_result();
			return 0;
	}
	
	function getFourImageGalerie($id_clinique) {
			$sql = "SELECT * FROM galerieImage WHERE id_clinique = ? LIMIT 0 , 4";			
			$Q = $this->db->query($sql, array($id_clinique));
			if ($Q->num_rows()>0){
				foreach ($Q->result_array() as $row){
					$data[]=$row;
				}
				return $data;
			}
			$Q->free_result();
			return 0;
	}
	
	function getNomInfoPatientId($id_patient) {
		$nom = "";
		$sql = "SELECT * FROM patient where id_patient = '$id_patient'";		
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$nom = $row['nom'];
			}
			return $nom;
		}
		$Q->free_result();
	}

	function getCivilitePatientId($id_patient) {
		$civilite = "";
		$sql = "SELECT * FROM patient where id_patient = '$id_patient'";		
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$civilite = $row['civilite'];
			}
			return $civilite;
		}
		$Q->free_result();
	}
	
	function getIpPaysPatientId($id_patient) {
		$id_pays = "";
		$sql = "SELECT * FROM patient where id_patient = '$id_patient'";		
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$id_pays = $row['id_pays'];
			}
			return $id_pays;
		}
		$Q->free_result();
	}
	
	function getIpVillePatientId($id_patient) {
		$id_ville = "";
		$sql = "SELECT * FROM patient where id_patient = '$id_patient'";		
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$id_ville = $row['id_ville'];
			}
			return $id_ville;
		}
		$Q->free_result();
	}
	
	function getDevisTableau($id_patient, $id_clinique, $reftableau) {
		$sql = "SELECT * FROM devistableau WHERE id_patient = '$id_patient' AND id_clinique = '$id_clinique' AND reftableau = '$reftableau'";			
		//echo $sql;
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function getDemandeDevisId($id_patient) {
		$sql = "SELECT * FROM demandeDevis WHERE id_patient = $id_patient";			
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}

	function getInfoClinicId($id_clinique) {
		$sql = "SELECT * FROM clinique WHERE id_clinique = $id_clinique";			
		//echo $sql;
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}

	function getPrixSoinsMisAvant($id_clinique) {
		$sql = "SELECT * FROM prixSoins WHERE id_clinique = $id_clinique AND typePrix = 1";			
		//echo $sql;
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function getPrixSoins1($id_clinique) {
		$sql = "SELECT * FROM prixSoins WHERE id_clinique = $id_clinique AND typePrix = 2";			
		//echo $sql;
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function getPrixSoins2($id_clinique) {
		$sql = "SELECT * FROM prixSoins WHERE id_clinique = $id_clinique AND typePrix = 3";			
		//echo $sql;
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}

	function getPrixSoins3($id_clinique) {
		$sql = "SELECT * FROM prixSoins WHERE id_clinique = $id_clinique AND typePrix = 4";			
		//echo $sql;
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}

	function getPrixSoins4($id_clinique) {
		$sql = "SELECT * FROM prixSoins WHERE id_clinique = $id_clinique AND typePrix = 5";			
		//echo $sql;
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function getPrixSoins5($id_clinique) {
		$sql = "SELECT * FROM prixSoins WHERE id_clinique = $id_clinique AND typePrix = 6";			
		//echo $sql;
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function getAllClinic(){
		$sql = "SELECT * FROM clinique WHERE isOK  = 1";			
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function getAllClinicFetch($limit, $start){
		$sql = "SELECT * FROM clinique WHERE isOK  = 1 LIMIT $start , $limit";			
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function getMultiClinicFetch($limit, $start, $p, $v){
		$sql = "";
		if ($v == 0 || $v == -1){
			$sql = "SELECT * FROM clinique WHERE isOK  = 1 AND id_pays = $p LIMIT $start , $limit";	
		}
		else {
			$sql = "SELECT * FROM clinique WHERE isOK  = 1 AND id_pays= $p AND id_ville = $v LIMIT $start , $limit";
		}
		//echo "mija :".$p.":".$v;			
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	public function count_nb_comments($id_clinique) {
        $sql = "SELECT * FROM commentaire WHERE id_clinique = '$id_clinique' AND isValid = 1 ";			
		$Q = $this->db->query($sql);
		$i=0;		
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
			$data[]=$row;
			$i++;
			}
		}
		$Q->free_result();
		return $i;
    }
    
    public function count_devis_envoye($id_patient) {
        $sql = "SELECT * FROM demandeDevis WHERE id_patient = '$id_patient'";			
		$Q = $this->db->query($sql);
		$i=0;		
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
			$data[]=$row;
			$i++;
			}
		}
		$Q->free_result();
		return $i;
    }
    
	public function record_count_getAllClinicFetch() {
        $sql = "SELECT * FROM clinique WHERE isOK = 1";			
		$Q = $this->db->query($sql);
		$i=0;		
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
			$data[]=$row;
			$i++;
			}
		}
		$Q->free_result();
		return $i;
    }
	
	public function record_count_getMultiClinicFetch($p, $v) {
		$sql = "";
		
		if ($v == 0 || $v == -1){
			$sql = "SELECT * FROM clinique WHERE isOK  = 1 AND id_pays = $p";	
		}
		else {
			$sql = "SELECT * FROM clinique WHERE isOK  = 1 AND id_pays = '$p' AND id_ville = '$v'";	
		}
		
		$Q = $this->db->query($sql);
		$i=0;		
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
			$data[]=$row;
			$i++;
			}
		}
		$Q->free_result();
		return $i;
    }
	
	

	function getAllPays(){
		$sql = "SELECT * FROM pays order by nom_pays asc";			
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function getAlllistSelectionClinic($id_patient) {
		$sql = "SELECT listclinic FROM  paginateClinic WHERE id_patient='$id_patient' ";		
		//echo $sql;		
		$Q = $this->db->query($sql);
		$i = 0;
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
					$i=$row['listclinic'];
			}
			return $i;
		}
		else {
			return 0;
		}
	}
	
	
	function getAllVille($id_pays){
		$sql = "SELECT * FROM ville Where id_pays = '$id_pays' ORDER BY nom_ville ASC";
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}

	function getAllVilleJson($id_pays) {
		$json = array();
		$data = array();
		$sql = "SELECT * FROM ville where id_pays = '$id_pays' ORDER BY nom_ville ASC";	
		//echo $sql;
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$json[$row['id_ville']][] = $row['nom_ville'];
			}
			$json = json_encode($json);
			
		}
		$Q->free_result();
		header('Content-Type: application/json');
		echo $json;
	}
	
	function selectNomVille($id_ville) {
		$nom = "";
		$sql = "SELECT * FROM ville where id_ville = '$id_ville'";		
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$nom = $row['nom_ville'];
			}
			return $nom;
		}
		$Q->free_result();
	}
	
	function selectNomClinique($id_clinique) {
		$nom = "";
		$sql = "SELECT * FROM clinique where id_clinique = '$id_clinique'";	
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$nom = $row['nom_clinique'];
			}
			return $nom;
		}
		$Q->free_result();
	}
	function selectNomPays($id_pays) {
		$nom = "";
		$sql = "SELECT * FROM pays where id_pays = '$id_pays'";		
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$nom = $row['nom_pays'];
			}
			return $nom;
		}
		$Q->free_result();
	}

	function deleteDentiste($id) {
		$this->db->delete("dentiste",array("id_dentiste"=>$id));
	}
	
	function deleteExp($id) {
		$this->db->delete("expProf",array("id_expProf"=>$id));
	}
	
	function deleteDemandeDevisR($id) {
		$this->db->delete("devisRecus",array("id_devisRecus"=>$id));
	}
	
	function deleteMessageClinic($id) {
		$this->db->delete("message",array("id_message"=>$id));
	}
	
	function deleteCommentaireClinic($id) {
		$this->db->delete("commentaire",array("id_commentaire"=>$id));
	}
	
	function updateLangueDentiste($id_dentiste, $Langage, $pos) {
		$data = array(
			'id_dentiste'=> $id_dentiste,
			'langue'.$pos=> $Langage
		);
	    $this->db->where('id_dentiste',$id_dentiste);
	    $this->db->update('dentiste', $data);
	}
	
	function updateIsValidClinic($email){
	    $data = array(
				'email' => $email,
				'isValid' => 1
			);
	    $this->db->where('email',$email);
	    $this->db->update('clinique', $data);
	} 
	
	function updateCommentaireClinic($id_commentaire){
	    $data = array(
				'id_commentaire' => $id_commentaire,
				'isValid' => 1
			);
	    $this->db->where('id_commentaire',$id_commentaire);
	    $this->db->update('commentaire', $data);
	} 
	
	function updateIsValidPatient($email){
	    $data = array(
				'email' => $email,
				'isValid' => 1
			);
	    $this->db->where('email',$email);
	    $this->db->update('patient', $data);
	} 
	
	function updateMaterielClinic($marque1, $marque2, $marque3, $origine1, $origine2, $origine3, $id_clinic){
		$data = array(
				'marque_implant1' => $marque1,
				'marque_implant2' => $marque2,
				'marque_implant3' => $marque3,
				'origine_materiaux1' => $origine1,
				'origine_materiaux2' => $origine2,
				'origine_materiaux3' => $origine3,
				'id_clinique' => $id_clinic
			);
	    $this->db->where('id_clinique',$id_clinic);
	    $this->db->update('clinique', $data);
	}
	
	function updateMaterielClinic1($marque1, $marque2, $marque3, $id_clinic){
		 $data = array(
				'marque_implant1' => $marque1,
				'marque_implant2' => $marque2,
				'marque_implant3' => $marque3,
				'id_clinique' => $id_clinic
			);
	    $this->db->where('id_clinique',$id_clinic);
	    $this->db->update('clinique', $data);
	}
	
	function updateMaterielClinic2($origine1, $origine2, $origine3, $id_clinic){
		 $data = array(
				'origine_materiaux1' => $origine1,
				'origine_materiaux2' => $origine2,
				'origine_materiaux3' => $origine3,
				'id_clinique' => $id_clinic
			);
	    $this->db->where('id_clinique',$id_clinic);
	    $this->db->update('clinique', $data);
	}
	
	function getprixSoins($id_clinique) {
			$sql = "SELECT * FROM  prixSoins WHERE id_clinique='$id_clinique' AND  	typePrix='1'";	
			$Q = $this->db->query($sql);
			if ($Q->num_rows()>0){
				foreach ($Q->result_array() as $row){
					$data[]=$row;
				}
				return $data;
			}
			$Q->free_result();
			return 0;
	}
	
	function getAllDevisRecus($id_clinique) {
		$sql = "SELECT * FROM devisRecus WHERE id_clinique = '$id_clinique'";			
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}

	function getAllMsgClinicRecus($id_clinique,$isMsgPatient) {
		$sql = "SELECT * FROM message WHERE id_clinique = '$id_clinique' AND isMsgPatient = '$isMsgPatient' ";			
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function getAllCommentairesClinicRecus($id_clinique) {
		$sql = "SELECT * FROM commentaire WHERE id_clinique = '$id_clinique' ";			
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function getAllMsgPatientRecus($id_patient,$isMsgClinique) {
		$sql = "SELECT * FROM message WHERE id_patient = '$id_patient' AND isMsgClinique = '$isMsgClinique' ";			
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function getAllDevisRecusPatient($id_patient) {
		$sql = "SELECT * FROM devisRecus WHERE id_patient = '$id_patient' AND typedevis = 1";			
		$Q = $this->db->query($sql);
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}	
	function getmodePaiement($id_clinique) {
			$sql = "SELECT * FROM  modePaiement WHERE id_clinique='$id_clinique'";	
			$Q = $this->db->query($sql);
			if ($Q->num_rows()>0){
				foreach ($Q->result_array() as $row){
					$data[]=$row;
				}
				return $data;
			}
			$Q->free_result();
			return 0;
	}
	function getprixSoinsAutres1($id_clinique, $sq) {
			$sql = "SELECT * FROM  prixSoins WHERE id_clinique='$id_clinique' AND typePrix='$sq' ";	
			$Q = $this->db->query($sql);
			if ($Q->num_rows()>0){
				foreach ($Q->result_array() as $row){
					$data[]=$row;
				}
				return $data;
			}
			$Q->free_result();
			return 0;
	}
	
	function verifPrixSoinsSave($id_clinique) {
		$sql = "SELECT * FROM  prixSoins WHERE id_clinique='$id_clinique' AND typePrix='1' ";			
		$Q = $this->db->query($sql);
		$i = 0;
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
					$data[]=$row;
					$i++;
			}
		}
		return $i;
	}

	function verifModePaiementSave($id_clinique) {
		$sql = "SELECT * FROM  modePaiement WHERE id_clinique='$id_clinique' ";			
		$Q = $this->db->query($sql);
		$i = 0;
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
					$data[]=$row;
					$i++;
			}
		}
		return $i;
	}
	
	function verifPrixSoinsSaveAutres($id_clinique) {
		$sql = "SELECT * FROM  prixSoins WHERE id_clinique='$id_clinique' AND typePrix='0' ";			
		$Q = $this->db->query($sql);
		$i = 0;
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
					$data[]=$row;
					$i++;
			}
		}
		return $i;
	}
	
	function verifPrixSoinsSaveAutres1($id_clinique, $sq) {
		$sql = "SELECT * FROM  prixSoins WHERE id_clinique='$id_clinique' AND typePrix='$sq' ";			
		$Q = $this->db->query($sql);
		$i = 0;
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
					$data[]=$row;
					$i++;
			}
		}
		return $i;
	}
	
	function insertExp ($data){
		return $this->db->insert('expProf', $data);
	}
	
	function insertprixSoinsSave ($data){
		return $this->db->insert('prixSoins', $data);
	}

	function insertMsgReponseClinic ($data){
		return $this->db->insert('message', $data);
	}
	
	function insertmodePaiementSave ($data){
		return $this->db->insert('modePaiement', $data);
	}
	
	
	
	function updateprixSoinsSave ($data1) {
	    $data = array(
			'intitule_soin'=> $data1['intitule_soin'],
			'prix_soin'=> $data1['prix_soin'], 
			'typePrix'=> $data1['typePrix']
		);
	    $this->db->where('id_prixSoins',$data1['id_prixSoins']);
	    $this->db->update('prixSoins', $data);
	}
	
	function deleteprixSoins($id) {
		$this->db->delete("prixSoins",array("id_prixSoins"=>$id));
	}
	
	function selectLanguedemandeDevis($id_patient, $i) {
		$sql = "SELECT langue$i FROM  demandeDevis WHERE id_patient='$id_patient'";		
		$Q = $this->db->query($sql);
		$langue = "";
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
					$langue=$row["langue$i"];
			}
		}
		return $langue;
	}
	
	function updateLanguedemandeDevis($butonLangage, $id_patient, $Langage, $id_Langage, $type) {
		$i = 1;
		if ($id_Langage == 2){
			$i = 2;
		}
		else if ($id_Langage == 3){
			$i = 3;
		}
		if ($butonLangage == "Non"){
			$Langage = "Selectionner";
		}
		$data = array(
			'id_patient'=> $id_patient,
			'langue'.$i=> $Langage
		);
	    $this->db->where('id_patient',$id_patient);
	    $this->db->update('demandeDevis', $data);
	}
	
	function selectImagedemandeDevis($id_patient, $i) {
		$sql = "SELECT photo$i FROM  demandeDevis WHERE id_patient='$id_patient'";		
		//echo $sql;
		$Q = $this->db->query($sql);
		$photo = "";
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
					$photo=$row["photo$i"];
			}
		}
		return $photo;
	}
	
	function updateImagedemandeDevis($butonPhotoDemande, $id_patient, $PhotoDemande, $id_PhotoDemande, $type){
	//function updateImagedemandeDevis($butonLangage, $id_patient, $Langage, $id_Langage, $type) {
		$i = 1;
		if ($id_PhotoDemande == 2){
			$i = 2;
		}
		else if ($id_PhotoDemande == 3){
			$i = 3;
		}
		else if ($id_PhotoDemande == 4){
			$i = 4;
		}
		else if ($id_PhotoDemande == 5){
			$i = 5;
		}
		if ($butonPhotoDemande == "Non"){
			$PhotoDemande = "";
		}
		$data = array(
			'id_patient'=> $id_patient,
			'photo'.$i=> $PhotoDemande
		);
	    $this->db->where('id_patient',$id_patient);
	    $this->db->update('demandeDevis', $data);
	}
	
	function getAllmodepaiement($id_clinique) {
		$sql = "SELECT * FROM   modePaiement WHERE id_clinique='$id_clinique'";	
		$Q = $this->db->query($sql);
		$data = array();
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
					$data[]=$row;
			}
			return $data;
		}
		else {
			return 0;
		}
		$Q->free_result();
	}
	
	function updatemodepaiement($id_modePaiement, $Langage){
		$data = array(
			'id_modePaiement' => $id_modePaiement, 	
			'type_paiement'=> $Langage
		);
		$this->db->where('id_modePaiement',$id_modePaiement);
		$this->db->update('modePaiement', $data);
	}
	
	function deletemodepaiement($id_modePaiement) {
		$this->db->delete("modePaiement",array("id_modePaiement"=>$id_modePaiement));
	}
	
	function verifPaginate($id_patient) {
		$sql = "SELECT id_paginateClinic FROM  paginateClinic WHERE id_patient='$id_patient' ";			
		//echo $sql;
		$Q = $this->db->query($sql);
		$i = 0;
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
					$i=$row['id_paginateClinic'];
			}
		}
		return $i;
	}
	
	function recupPaginate($id_paginateClinic) {
		$sql = "SELECT listclinic FROM  paginateClinic WHERE id_paginateClinic='$id_paginateClinic' ";		
		//echo $sql;		
		$Q = $this->db->query($sql);
		$i = 0;
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
					$i=$row['listclinic'];
			}
			return $i;
		}
		else {
			return 0;
		}
	}
	
	function insertpaginateClinic($data){
		return $this->db->insert('paginateClinic', $data);
	}
	
	function updatepaginateClinic($id_paginateClinic, $listclinic){
		$data = array(
			'id_paginateClinic' => $id_paginateClinic, 	
			'listclinic'=> $listclinic
		);
		$this->db->where('id_paginateClinic',$id_paginateClinic);
		$this->db->update('paginateClinic', $data);
	}
	
	function recupEmailPatient($id_patient) {
		$sql = "SELECT email FROM patient WHERE id_patient ='$id_patient'  ";
		//echo $sql;
		$Q = $this->db->query($sql);
		$email = "";
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$email = $row['email'];
			}
		}
		$Q->free_result();
		return $email;
	} 
	
	function verifEmailComptePatient($email) {
		$sql = "SELECT id_patient FROM patient WHERE email ='$email'  ";
		//echo $sql;
		$Q = $this->db->query($sql);
		$email = "";
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$id_patient = $row['id_patient'];
			}
		}
		$Q->free_result();
		return $id_patient;
	} 
	
	function verifEmailCompteClinique($email) {
		$sql = "SELECT id_clinique FROM clinique WHERE email ='$email'  ";
		//echo $sql;
		$Q = $this->db->query($sql);
		$email = "";
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$id_clinique = $row['id_clinique'];
			}
		}
		$Q->free_result();
		return $id_clinique;
	} 
	
	function recupEmailClinic($id_clinique) {
		$sql = "SELECT email FROM clinique WHERE id_clinique ='$id_clinique'  ";
		$Q = $this->db->query($sql);
		$email = "";
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$email = $row['email'];
			}
		}
		$Q->free_result();
		return $email;
	}
	
	function recupClinic($id_clinique) {
		$sql = "SELECT * FROM clinique WHERE id_clinique ='$id_clinique'  ";
		$Q = $this->db->query($sql);
		$data = array();
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[] = $row;
			}
		}
		$Q->free_result();
		return $data;
	}
	
	function deletepaginateClinic($id_patient) {
		$this->db->delete("paginateClinic", array("id_patient"=>$id_patient));
	}
	
	function insertDevisRecu($data){
		return $this->db->insert('devisRecus', $data);
	}
	
	function verfIdClinicPaginate($id_patient, $id_clinic){
		$value = $this->MDn->verifPaginate($id_patient);
		if ($value!=0){
			$new = $this->MDn->recupPaginate($value);
			$input = explode(",", $new);
			$result = array_unique($input);
			foreach($result as $list){
				if ($list == $id_clinic){
					return true;
				}
			}
		}
		return false;
	}
	
	function verifdevisRecus($id_patient, $id_clinic) {
		$sql = "SELECT * FROM  devisRecus WHERE id_patient='$id_patient' AND id_clinique = '$id_clinic'";	
		//echo $sql;
		$Q = $this->db->query($sql);
		$i = 0;
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
					//$i=$row['id_devisRecus'];
					$i++;
			}
		}
		return $i;
	}
	
	function deleteGalerie($id_galerieImage) {
		$this->db->delete("galerieImage", array("id_galerieImage"=>$id_galerieImage));
	}
	
	function deleteSoin($id_photoSoin) {
		$this->db->delete("photoSoin", array("id_photoSoin"=>$id_photoSoin));
	}
}//end class
?>